from abc import ABCMeta, abstractmethod


class BaseError(Exception):
    def __init__(self, request_item):
        self.request_item = request_item


class ForbiddenError(BaseError):
    def __init__(self, request_item):
        super().__init__(request_item)
    pass


class NotFoundError(BaseError):
    def __init__(self, request_item):
        super().__init__(request_item)


class TimeoutError(BaseError):
    def __init__(self, request_item):
        super().__init__(request_item)
    pass


class ResultIllegalError(Exception):
    """
    结果不正确(指服务端没有给我们正确的信息, 抛出这个异常, 爬虫尝试换header继续爬
    """
    def __init__(self, request_item):
        super().__init__(request_item)


class ExceptionHandler(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def handler(self, exception, download, **kwargs):
        pass


class DefaultExceptionHandler(ExceptionHandler):
    def handler(self, exception, download, **kwargs):

        pass